package com.hula.onion.book.server.spider.platforms.weidaiwang;

import com.hula.onion.book.server.common.LoginForm;
import com.hula.onion.book.server.utils.RegexParserUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.Base64Utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 * Create Date:2018/1/17 19:49
 *
 * @author shan
 * @version 1.0
 */
@Component
public class WeiDaiWangSpiderHelper {

    /**
     * 组装请求参数
     *
     * @param form
     * @return
     */
    public Map<String, Object> installRequestParams(LoginForm form) throws Exception {

        Map<String, Object> map = new HashMap<>(3);

        map.put("userName", form.getUserName());
        map.put("password", Base64Utils.encodeToString(form.getPassword().getBytes()));
        map.put("loginCode", "");

        return map;

    }

    /**
     * 解析账户余额
     *
     * @param html
     * @return
     */
    public String parseAccountBalance(String html) {
        String beginRegex = "<span class=\"font-orange DinFont\" id=\"total-money\">";
        String endRegex = "</span>";
        String result = new RegexParserUtils(beginRegex, endRegex, html, RegexParserUtils.TEXTTEGEX).getText();

        return result;
    }


}
